package com.zmj.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ListService {
    @Autowired
    RedisTemplate<String,String> redisTemplate;

    public void getNews(){
        List<String> list=new ArrayList<>();
        list.add("aaaaa");
        list.add("bbbb");
        list.add("cccccc");
        list.add("ddddd");
        list.add("eeeee");
        redisTemplate.opsForList().leftPushAll("news:top5",list);
    }

    public void addNews(){
        redisTemplate.opsForList().leftPush("news:top5","1111111");
    }



    //####################################TODO


    public List<String> getAddress(String cardId ){
        String key =cardId+":queue";//初始化队列
        redisTemplate.opsForList().leftPush(key,"1. 上海站");
        redisTemplate.opsForList().leftPush(key,"2. 苏州站");
        redisTemplate.opsForList().leftPush(key,"3. 南京站");
        redisTemplate.opsForList().leftPush(key,"4. 芜湖站");
        redisTemplate.opsForList().leftPush(key,"5. 许镇");
        redisTemplate.opsForList().leftPush(key,"6. 收货");
        return redisTemplate.opsForList().range(key,0,-1);
    }

    public String touchQueue(String cardId){
        String key =cardId+":queue";//初始化队列
        String key1 =cardId+":carryOut";
       return redisTemplate.opsForList().rightPopAndLeftPush(key,key1);
    }

    /**
     * 功能描述: <br>
     * 〈〉
     *
     查询还有多少站到
     * @return:List 集合
     * @since: 1.0.0
     * @Author:朱明洁
     * @Date: 2020年7月28日20:40:50
     */
    public List<String> selQueue(String cardId){
        String key =cardId+":queue";//初始化队列
        return redisTemplate.opsForList().range(key,0,-1);
    }


    /**
     * 功能描述: <br>
     * 〈〉
     *
     查询到货物哪里了
     * @return:String
     * @since: 1.0.0
     * @Author:朱明洁
     * @Date:  2020年7月28日20:45:02
     */
    public List<String> selAddress(String cardId){
        String key1 =cardId+":carryOut";
        return  redisTemplate.opsForList().range(key1,0,-1);
    }
}
